package controllers

import "beego_project/models"

type IndexController struct {
	BaseController
}

// @router / [get]
func (this *IndexController) Index() {
	// limit, 暂时默认每页显示10条数据
	limit := 5
	// page
	page, err := this.GetInt("page", 1)
	if err != nil || page <= 0 {
		page = 1
	}
	// 拿到查询关键字
	title := this.GetString("title")

	notes, _ := models.QueryNotesByPage(title, page, limit)
	this.Data["notes"] = notes
	// 查询文章总数量
	count, _ := models.QueryNotesCount(title)
	totPage := count / limit
	if count%limit != 0 {
		totPage += 1 // 也可以math.ceiling
	}
	this.Data["totPage"] = totPage
	this.Data["page"] = page
	this.Data["title"] = title
	this.TplName = "index.html"
}

// @router /about [get]
func (this *IndexController) About() {
	this.TplName = "about.html"
}

// @router /comment [get]
func (this *IndexController) Comment() {
	this.TplName = "comment.html"
}

// @router /message [get]
func (this *IndexController) Message() {
	this.TplName = "message.html"
}

// @router /details [get]
func (this *IndexController) Details() {
	this.TplName = "details.html"
}

// @router /user [get]
func (this *IndexController) User() {
	this.TplName = "user.html"
}

// @router /register [get]
func (this *IndexController) Register() {
	this.TplName = "register.html"
}
